package com.chidopi.cdf.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

public class DefaultUser implements Serializable, UserDetails {
	private static final long serialVersionUID = 1L;
	private String name;
    private String password;
    private Set<Authority> roles;
 
    public DefaultUser(String name, String password) {
        this.name = name;
        this.password = password;
    }
	
	public Collection<GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
        for (Authority role : roles) 
              list.add(new GrantedAuthorityImpl(role.getAuthority()));
        return list;
	}
	
	public Set<Authority> getRoles() {
        return roles;
    }

	public void setRoles(Set<Authority> roles) {
        this.roles = roles;
    }

    public String getPassword() {
        return password;
    }

    public String getUsername() {
        return name;
    }

    public boolean isAccountNonExpired() {
        return true;
    }

    public boolean isAccountNonLocked() {
        return true;
    }

    public boolean isCredentialsNonExpired() {
        return true;
    }

    public boolean isEnabled() {
        return true;
    }

}
